package com.google.wave.robot.scrimborg;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import java.util.regex.Pattern;

public class EmailDetector {
	
	private static final Logger log = Logger.getLogger( EmailDetector.class.getSimpleName( ) );
 
	private static final Pattern pattern = Pattern.compile( "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$", Pattern.CASE_INSENSITIVE ); 
	
	public static List<String> parse( String text ){
		
		List<String> emails = new ArrayList<String>( );
		
		for ( String word : text.split( " ") ) {
			if( pattern.matcher( word ).matches( ) ) {
				emails.add( word );
				log.info( "email found: "+ word );
			}
		}
		
		return emails.size( ) > 0 ? emails : null ;

	}
}
